package com.pro.controller;

import com.pro.pojo.JsMicrocircle;
import com.pro.pojo.JsonData;
import com.pro.service.JsMicrocircleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/JsMicrocircle")
public class JsMicrocircleController {
    @Autowired
    JsMicrocircleService jms;
    @RequestMapping(value = "/getAllJsMicrocircle")
    @ResponseBody
    public JsonData getAllJsMicrocircle(JsMicrocircle param){
        List<JsMicrocircle> allJsMicrocircle = jms.getAllJsMicrocircle(param);
        return allJsMicrocircle != null? com.pro.pojo.JsonData.buildSuccess(allJsMicrocircle): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //根据文章id查询收藏量
    @RequestMapping(value = "/getCollectionBasedOnId")
    @ResponseBody
    public JsonData getCollectionBasedOnId(Integer microcircleId){
        Integer collectionBasedOnId = jms.getCollectionBasedOnId(microcircleId);
        return collectionBasedOnId != null? com.pro.pojo.JsonData.buildSuccess(collectionBasedOnId): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //根据id删除一条数据
    @RequestMapping(value = "/deleteByIdJsMicrocircle")
    @ResponseBody
    public JsonData deleteByIdJsMicrocircle(Integer microcircleId){
        boolean b = jms.deleteByIdJsMicrocircle(microcircleId);
        return b? com.pro.pojo.JsonData.buildSuccess(b): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //添加一条微圈信息草稿
    @RequestMapping(value = "/addJsMicrocircle")
    @ResponseBody
    public JsonData addJsMicrocircle(JsMicrocircle layForm){
        boolean b = jms.addJsMicrocircle(layForm);
        return b? com.pro.pojo.JsonData.buildSuccess(layForm): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //修改一条微圈信息
    @RequestMapping(value = "/updateJsMicrocircle")
    @ResponseBody
    public JsonData updateJsMicrocircle(JsMicrocircle layForm){
        boolean b = jms.updateJsMicrocircle(layForm);
        return b? com.pro.pojo.JsonData.buildSuccess(layForm): com.pro.pojo.JsonData.buildError("服务器异常");
    }

    //查看当前用户是否有草稿状态信息
    @RequestMapping(value = "/getJsMicrocircle")
    @ResponseBody
    public JsonData getJsMicrocircle(Integer userId){
        JsMicrocircle jsMicrocircle = jms.getJsMicrocircle(userId);
        return jsMicrocircle != null? com.pro.pojo.JsonData.buildSuccess(jsMicrocircle): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //根据状态进行模糊查
    @RequestMapping(value = "/getJsMicrocircleByStatus")
    @ResponseBody
    public JsonData getJsMicrocircleByStatus(JsMicrocircle param) {
        List<JsMicrocircle> jsMicrocircle = jms.getJsMicrocircleByStatus(param);
        return jsMicrocircle != null? com.pro.pojo.JsonData.buildSuccess(jsMicrocircle): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //根据状态进行模糊查
    @RequestMapping(value = "/getJsMicrocircleSuperSearch")
    @ResponseBody
    public JsonData getJsMicrocircleSuperSearch(JsMicrocircle param) {
        List<JsMicrocircle> jsMicrocircleSuperSearch = jms.getJsMicrocircleSuperSearch(param);
        return jsMicrocircleSuperSearch != null? com.pro.pojo.JsonData.buildSuccess(jsMicrocircleSuperSearch): com.pro.pojo.JsonData.buildError("服务器异常");
    }
    //根据微圈Id获取微圈评论次数
    @RequestMapping(value = "/countMicroCircleComment")
    @ResponseBody
    public JsonData countMicroCircleComment(Integer commodityId) {
        int i = jms.countMicroCircleComment(commodityId);
        return i != 0 ? com.pro.pojo.JsonData.buildSuccess(i): com.pro.pojo.JsonData.buildError("0");
    }
    //根据状态获取每种状态的个数
    @RequestMapping(value = "/countDetails")
    @ResponseBody
    public JsonData countDetails(Integer details)  {
        int i = jms.countDetails(details);
        return i != 0 ? com.pro.pojo.JsonData.buildSuccess(i): com.pro.pojo.JsonData.buildError("0");
    }
    //根据状态获取每种状态的个数
    @RequestMapping(value = "/getByIdAllJsMicrocircle")
    @ResponseBody
    public JsonData getByIdAllJsMicrocircle(JsMicrocircle layForm) {

        List<JsMicrocircle> byIdAllJsMicrocircle = jms.getByIdAllJsMicrocircle(layForm);
        return byIdAllJsMicrocircle!=null ? com.pro.pojo.JsonData.buildSuccess(byIdAllJsMicrocircle): com.pro.pojo.JsonData.buildError("0");
    }
    //根据状态获取每种状态的个数
    @RequestMapping(value = "/getAllMicroCircleUpperCount")
    @ResponseBody
    public JsonData getAllMicroCircleUpperCount() {

        int allMicroCircleUpperCount = jms.getAllMicroCircleUpperCount();
        return allMicroCircleUpperCount!=0 ? com.pro.pojo.JsonData.buildSuccess(allMicroCircleUpperCount): com.pro.pojo.JsonData.buildError("0");
    }
}
